package com.hyt.it.ogt.kq.main.controller.bm;

import java.io.IOException;
import java.io.InputStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.hyt.it.ogt.kq.service.bm.feign.file.FileClient;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "文件服务器接口（不要直接调用）")
@RestController
@RequestMapping("/file")
public class FileController {
	
	@Autowired
	private FileClient fileClient;

	@ApiOperation(value = "上传MultipartFile", notes = "返回文件路径")
	@RequestMapping(value = "/upload/multipartfile",
		method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	public String uploadFile(@RequestPart(value = "file") MultipartFile file) throws IOException {
		return fileClient.uploadFile(file);
	}
	
	@ApiOperation(value = "把字符串作为指定格式的文件上传", notes = "返回文件路径")
	@RequestMapping(value = "/upload/string", method = RequestMethod.POST)
	public String uploadFile(String content, String fileExtension) {
		return fileClient.uploadFile(content, fileExtension);
	}
	
	@ApiOperation(value = "上传图片并生成缩略图", notes = "返回文件路径")
	@RequestMapping(value = "/upload/image/crtthumbimage",
		method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	public String uploadImageAndCrtThumbImage(@RequestPart(value = "file") MultipartFile file) throws IOException {
		return fileClient.uploadImageAndCrtThumbImage(file);
	}
	
	@ApiOperation(value = "根据图片路径获取缩略图路径", notes = "返回缩略图路径")
	@RequestMapping(value = "/get/thumbimagepath", method = RequestMethod.GET)
	public String getThumbImagePath(String filePath) {
		return fileClient.getThumbImagePath(filePath);
	}
	
	@ApiOperation(value = "根据文件路径删除文件", notes = "添加考生基本信息")
	@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
	public void deleteFile(String filePath) {
		fileClient.deleteFile(filePath);
	}

	@ApiOperation(value = "根据文件路径获取文件", notes = "根据文件路径获取文件")
	@RequestMapping(value = "/downFileByStream", method = RequestMethod.GET)
	public InputStream downFileByStream(String filePath) {
		return fileClient.downFileByStream(filePath);
	}




}
